package cn.ac.cintcm.dataconverge.researcher.service.impl;

import java.util.List;

import cn.ac.cintcm.dataconverge.dao.IBaseDao;
import cn.ac.cintcm.dataconverge.researcher.dao.IResearcherDao;
import cn.ac.cintcm.dataconverge.researcher.domain.Researcher;
import cn.ac.cintcm.dataconverge.researcher.form.ResearcherSchForm;
import cn.ac.cintcm.dataconverge.researcher.service.IResearcherService;
import cn.ac.cintcm.dataconverge.util.Constants;
import cn.ac.cintcm.dataconverge.util.MD5;

import com.hs.core.page.PageParam;
import com.hs.core.page.PageUtil;
import com.hs.core.service.BaseSevice;

public class ResearcherService extends BaseSevice implements IResearcherService{

	private IResearcherDao researcherDao;
	
	public IResearcherDao getResearcherDao() {
		return researcherDao;
	}

	public void setResearcherDao(IResearcherDao researcherDao) {
		this.researcherDao = researcherDao;
	}

	public void addResearcher(Researcher researcher) {
		researcherDao.save(researcher);
	}

	public List getResearchers(String orgId, String zhicheng,String name) {
		return researcherDao.getResearchers(orgId,zhicheng,name);
	}

	public List getResearchersByDepartment(String id) {
		// TODO Auto-generated method stub
		return researcherDao.getResearchersByDepartment(id);
	}

	public Researcher getResearcherByid(String id) {
		// TODO Auto-generated method stub
		//System.out.println();
		return researcherDao.getResearcherById(id);
	}

	public void deleteResearcher(String id) {
		researcherDao.delete(researcherDao.getResearcherById(id));
		
	}

	public List getDepartmentsByOrgId(Long orgId) {
		return researcherDao.getDepartmentsByOrgId(orgId);
	}
	
	public static void main(String args[]){
		ResearcherService res=new ResearcherService();
		Researcher researcher=new Researcher();
		res.addResearcher(researcher);
	}

	public boolean updateresearcher(Researcher re) {
		// TODO Auto-generated method stub
		researcherDao.update(re);
		return true; 
	}

    /* (non-Javadoc)
     * @see cn.ac.cintcm.dataconverge.researcher.service.IResearcherService#checkUserLogin(java.lang.String, java.lang.String)
     */
    public String checkUserLogin(String id, String password) {
//        Md5PasswordEncoder md5 = new Md5PasswordEncoder();
//        String pswdEncode = md5.encodePassword(password, "12345");
        String md5pass = MD5.md5(password);
        String rtCode = "permit";
//        List list = researcherDao.getResearcherListById(id);
        
        Researcher user = researcherDao.getResearcherById(id);
        System.out.print("md5pass:" + MD5.md5("1"));
         
//        System.out.println("in the checkuselogin "+list);
//        if(null == user)
//        	return rtCode=Constants.MESSAGE_REGISTER_FIRST;     
        if (user == null) {
            rtCode = Constants.MESSAGE_LOG_USER_NOT_EXIST;
        }
        else {
        	String pswdEncode = user.getPassword();
        	String userStatus = user.getStatus();
            if (!md5pass.equalsIgnoreCase(pswdEncode)) 
            {
            	rtCode = Constants.MESSAGE_LOG_WRONG_PASSWORD;
            }     
            System.out.println("userStatus:" + userStatus);
            if(!"system".equals(user.getIda()) && !"Y".equals(userStatus)){
            	rtCode = Constants.MESSAGE_LOG_NOTALIVE;
            }
        }
        return rtCode;
    }

	public Long getOrgbyUser(String id) {
		// TODO Auto-generated method stub
		return researcherDao.geOrgbyUser(id);
	}

	public List getResearcherByIdcard(String idcard,String status) {
		// TODO Auto-generated method stub
		List rst=researcherDao.getResearcherByIdcard(idcard,status);
		return rst;
	}

	public List getResearcherByIdcardAndName(String name, String idcard,String status) {
		// TODO Auto-generated method stub
		return researcherDao.getResearcherByIdcardAndName(name,idcard,status);
	}

	public List getResearcherByName(String name,String status) {
		// TODO Auto-generated method stub
		return researcherDao.getResearcherByName(name,status);
	}

	public void deleteResearcher(Long ids) {
		// TODO Auto-generated method stub
		Researcher res=researcherDao.getResearcherByIds(ids);
		researcherDao.delete(res);
		
	}

	public Researcher getResearcherByids(Long ids) {
		// TODO Auto-generated method stub
		return researcherDao.getResearcherByIds(ids);
	}

	public List getResearcherListByid(String id) {
		// TODO Auto-generated method stub
		System.out.println("in the service method!!!!!!!!!!!!!");
		return researcherDao.getResearcherListById(id);
	}

	public List getResearchersByOrg(Long org) {
		// TODO Auto-generated method stub
		return researcherDao.getResearchersByOrg(org);
	}

	public Researcher getResearcherByNameAndIdcard(String name, String idcard) {
		// TODO Auto-generated method stub
		return researcherDao.getResearcherByNameAndIdcard(name,idcard);
	}

	public boolean getResearcherByNameAndIdcard(String name, String idcard, Long i) {
		// TODO Auto-generated method stub
		return researcherDao.getResearcherByNameAndIdcard(name, idcard, i);
	}

	public String addNewResearcher(Researcher re) {
		// TODO Auto-generated method stub
		return researcherDao.addNewResearcher(re);
	}

	public Researcher getResearcherByIdcard(String idcard) {
		// TODO Auto-generated method stub
		return researcherDao.getResearcherByIdcard(idcard);
	}

	public List schResearcherByForm(ResearcherSchForm form) {
		// TODO Auto-generated method stub
		return researcherDao.getResearcherByForm(form);
	}

	public String getResIds(String resNames, Long orgId, String zhicheng) {
		return researcherDao.dealWithResNames(resNames,orgId,zhicheng);
	}

	public int countResByOrg(Long orgId) {
		return researcherDao.countResByOrg(orgId);
	}

	@Override
	public IBaseDao getBaseDao() {
		// TODO Auto-generated method stub
		return researcherDao;
	}

	public PageUtil getResearcherList(PageParam pageParam) {
		// TODO Auto-generated method stub
		return researcherDao.getResearcherList(pageParam);
	}
	 
}
